# coding=UTF-8
__author__ = 'Administrator'
import random


def make_news_one(id):
    # path = r'.\textlive\xinlang2\{}'.format(id)
    path = r'C:\Users\Administrator\Desktop\WriteBot\untitled\textlive\xinlang2\{}'.format(id)
    file = open(path, mode='r')
    data = []
    sentences = file.readlines()
    sentences.reverse()
    for line in sentences:
        l = line.replace('\t', ' ').strip().split(' ')
        if len(l) == 4 and l[2] != '未开始' and len(l[3]) >= 3 and len(l[2]) != 0 and l[2] != '已结束':
            data.append(l)
    # print data[0]

    print(data[0][-1].strip().split('-')[0])
    print(data[0][-1].strip().split('-')[1])
    pre1 = int(data[0][-1].strip().split('-')[0])
    pre2 = int(data[0][-1].strip().split('-')[1])
    tag = 0
    description = []
    quarter1_news = []
    quarter2_news = []
    quarter3_news = []
    quarter4_news = []
    overtime_news = []
    first_start = '首节比赛期间，'
    second_start = '次节比赛期间，'
    third_start = '第三节比赛期间，'
    forth_start = '末节比赛期间，'
    overtime_start = '加时赛期间，'
    first_end = ''
    second_end = ''
    third_end = ''
    forth_end = ''
    overtime_end = ''
    for d, i in zip(data, range(len(data))):
        if d[2] == '第一节':
            score1 = int(d[-1].strip().split('-')[0])
            score2 = int(d[-1].strip().split('-')[1])
            if score1 - pre1 >= 2 or score2 - pre2 >= 2:
                if i - tag >= 3:
                    description.append(data[i - 2][1])
                    description.append(data[i - 1][1])
                    description.append(data[i][1])
                    description.append(data[i][3])
                    quarter1_news.append(description)
                    description = []
                    tag = i
                else:
                    tag = i
        elif d[2] == '第二节':
            first_end = '首节打完，双方比分' + data[i - 1][-1]
            score1 = int(d[-1].strip().split('-')[0])
            score2 = int(d[-1].strip().split('-')[1])
            if score1 - pre1 >= 2 or score2 - pre2 >= 2:
                if i - tag >= 3:
                    description.append(data[i - 2][1])
                    description.append(data[i - 1][1])
                    description.append(data[i][1])
                    description.append(data[i][3])
                    quarter2_news.append(description)
                    description = []
                    tag = i
                else:
                    tag = i
        elif d[2] == '第三节':
            second_end = '次节打完，双方比分' + data[i - 1][-1]
            score1 = int(d[-1].strip().split('-')[0])
            score2 = int(d[-1].strip().split('-')[1])
            if score1 - pre1 >= 2 or score2 - pre2 >= 2:
                if i - tag >= 3:
                    description.append(data[i - 2][1])
                    description.append(data[i - 1][1])
                    description.append(data[i][1])
                    description.append(data[i][3])
                    quarter3_news.append(description)
                    description = []
                    tag = i
                else:
                    tag = i
        elif d[2] == '第四节':
            third_end = '第三节打完，双方比分' + data[i - 1][-1]
            score1 = int(d[-1].strip().split('-')[0])
            score2 = int(d[-1].strip().split('-')[1])
            if score1 - pre1 >= 2 or score2 - pre2 >= 2:
                if i - tag >= 3:
                    description.append(data[i - 2][1])
                    description.append(data[i - 1][1])
                    description.append(data[i][1])
                    description.append(data[i][3])
                    quarter4_news.append(description)
                    description = []
                    tag = i
                else:
                    tag = i
        else:
            forth_end = '末节打完，双方比分' + data[i - 1][-1]
            score1 = int(d[-1].strip().split('-')[0])
            score2 = int(d[-1].strip().split('-')[1])
            if score1 - pre1 >= 2 or score2 - pre2 >= 2:
                if i - tag >= 3:
                    description.append(data[i - 2][1])
                    description.append(data[i - 1][1])
                    description.append(data[i][1])
                    description.append(data[i][3])
                    overtime_news.append(description)
                    description = []
                    tag = i
                else:
                    tag = i

        pre1 = score1
        pre2 = score2
    q_n1 = ['，'.join(i) for i in [random.choice(quarter1_news[:len(quarter1_news) // 3]),
                                  random.choice(quarter1_news[len(quarter1_news) // 3 + 1:2 * len(quarter1_news) // 3]),
                                  random.choice(quarter1_news[2 * len(quarter1_news) // 3 + 1:])]]
    q_n2 = ['，'.join(i) for i in [random.choice(quarter2_news[:len(quarter2_news) // 3]),
                                  random.choice(quarter2_news[len(quarter2_news) // 3 + 1:2 * len(quarter2_news) // 3]),
                                  random.choice(quarter2_news[2 * len(quarter2_news) // 3 + 1:])]]
    q_n3 = ['，'.join(i) for i in [random.choice(quarter3_news[:len(quarter3_news) // 3]),
                                  random.choice(quarter3_news[len(quarter3_news) // 3 + 1:2 * len(quarter3_news) // 3]),
                                  random.choice(quarter3_news[2 * len(quarter3_news) // 3 + 1:])]]
    q_n4 = ['，'.join(i) for i in [random.choice(quarter4_news[:len(quarter4_news) // 3]),
                                  random.choice(quarter4_news[len(quarter4_news) // 3 + 1:2 * len(quarter4_news) // 3]),
                                  random.choice(quarter4_news[2 * len(quarter4_news) // 3 + 1:])]]
    if len(overtime_news) != 0:
        o_n = ['，'.join(i) for i in [random.choice(overtime_news[:len(overtime_news) // 3]), random.choice(
            overtime_news[len(overtime_news) // 3 + 1:2 * len(overtime_news) // 3]),
                                     random.choice(overtime_news[2 * len(overtime_news) // 3 + 1:])]]
    news = first_start + '。'.join(q_n1) + '。' + first_end + '\n' + second_start + '。'.join(
        q_n2) + '。' + second_end + '\n' + third_start + '。'.join(
        q_n3) + '。' + third_end + '\n' + forth_start + '。'.join(q_n4) + '。' + forth_end + '\n'
    if len(overtime_news) != 0:
        news = news + overtime_start + '。'.join(o_n) + '。'
    print(news.replace('！', ''))


if __name__ == '__main__':
    while True:
        print('请输入id：')
        id = input()
        if id == '0':
            break
        make_news_one(id)
